<?php

namespace app\common\dao\lawyer;

use app\common\model\lawyer\Lawyer as model;
use app\common\dao\BaseDao;

class LawyerDao extends BaseDao
{
    /**
    * 设置模型
    * @return model
    */
    protected function getModel(): string
    {
        return model::class;
    }

    public function getByUid($uid)
    {
        return ($this->getModel())::getDB()->where('uid',$uid)->find();
    }

    public function search($where)
    {
        $query = $this->getModel()::getDB();
        $query->when(isset($where['city_id']) && $where['city_id'] !== '', function ($query)use($where){
            $query->where('city_id',$where['city_id']);
        })->when(isset($where['name']) && $where['name'] !== '', function ($query)use($where){
            $query->where('name','like',"%{$where['name']}%");
        })->when(isset($where['phone']) && $where['phone'] !== '', function ($query)use($where){
            $query->where('phone','like',"%{$where['phone']}%");
        })->when(isset($where['main_do']) && $where['main_do'] !== '', function ($query)use($where){
            $query->where('main_do','like',"%{$where['main_do']}%");
        })->when(isset($where['status']) && $where['status'] !== '', function ($query)use($where){
            $query->where('status',$where['status']);
        })->when(isset($where['recommend']) && $where['recommend'] !== '', function ($query)use($where){
            $query->where('recommend',$where['recommend']);
        });

        return $query;
    }


}